<?php

class ArticleDAO {
	public function findById($id) {
		// SELECT * FROM article WHERE id = ...
	}
	public function findByTitle($title) {
		// SELECT * FROM article WHERE title LIKE ...
	}
}

class ArticleCache {
	protected $cache;
	protected $dao;
	public function __construct($cache, $dao) {
		$this->cache = $cache;
		$this->dao = $dao;
	}
	public function findById($id) {
		$key = 'id_' . $id;
		if (! ($result = $this->cache->get ( $key ))) {
			$result = $this->cache->findById ( $id );
			$this->cache->set ( $key, $result );
		}
		return $result;
	}
	public function findByTitle($title) {
		$key = 'title_' . $title;
		if (! ($result = $this->cache->get ( $key ))) {
			$result = $this->cache->findByTitle ( $title );
			$this->cache->set ( $key, $result );
		}
		return $result;
	}
}
$memcache = new Memcache ( );
$memcache->connect ( 'host', 'port' );
$dao = new ArticleDAO ( );
$cache = new ArticleCache ( $memcache, $dao );
$cache->findById ( 'id' );
$cache->findByTitle ( 'title' );

class Cache {
	protected $cache;
	protected $dao;
	public function __construct($cache, $dao) {
		$this->cache = $cache;
		$this->dao = $dao;
	}
	public function __call($name, $arguments) {
		if (strtolower ( substr ( $name, 0, 4 ) ) != 'find') {
			return false;
		}
		$key = md5 ( strtolower ( get_class ( $this->dao ) . $name . serialize ( $arguments ) ) );
		if (! ($result = $this->cache->get ( $key, $flags ))) {
			$result = call_user_func_array ( array ($this->dao, $name ), $arguments );
			$this->cache->set ( $key, $result );
		}
		return $result;
	}
}
$memcache = new Memcache ( );
$memcache->connect ( 'host', 'port' );
$dao = new ArticleDAO ( );
$cache = new Cache ( $memcache, $dao );
$cache->findById ( 'id' );
$cache->findByTitle ( 'title' ); 